package com.swt.controller.S_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.User;
import com.swt.domain.Vipcard;
import com.swt.service.S_service.AddVipCardService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AddVipCardController {
    /*注入service*/
    @Resource(name = "S_addVipCardService")
    private AddVipCardService addVipCardService;
    /*申请会员卡的controller*/
    @RequestMapping("/S_addVipCard")
    public  String addVipCard(Vipcard vipcard, HttpServletRequest request){
        /*设置是属于哪一个用户*/
        User user = (User)request.getSession().getAttribute("USER_SESSION_KEY");
        vipcard.setVipcardUserId(user.getUserId());
        /*设置状态为待审核*/
        vipcard.setVipcardStatus("使用中");
        /*调用service*/
        addVipCardService.addVipCard(vipcard);
        return "redirect:/user/vipcard.html";
    }
    /*获取该店铺下的该用户的会员卡*/
    @RequestMapping("/S_getVipCard")
    @ResponseBody
    public  String getVipCard(int clubid,HttpServletRequest request){
        User user = (User)request.getSession().getAttribute("USER_SESSION_KEY");
        int userid=user.getUserId();
        /*调用service*/
        List<Vipcard> vipCard = addVipCardService.getVipCard(userid, clubid);
        String list=JSON.toJSONString(vipCard);
        return list;
    }
}
